package ln.fxspringarchetype.controller.score;

import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import ln.fxspringarchetype.controller.BaseFxController;
import ln.fxspringarchetype.vo.ScoreVO;
import org.apache.logging.log4j.util.Strings;

import java.util.Objects;

public class DeleteScoreController extends BaseFxController {
    private final ScoreVO scoreVO = new ScoreVO();
    @FXML
    private Label idLabel;
    @FXML
    private Label studentNameLabel;
    @FXML
    private Label courseNameLabel;
    @FXML
    private Label examDateLabel;
    @FXML
    private Label scoreLabel;

    public ScoreVO getScoreVO() {
        return scoreVO;
    }

    @Override
    public void setCellValueFactories() {

    }

    @Override
    public void setCellFactories() {

    }

    @Override
    public void createBindings() {
        idLabel.textProperty().bind(
                Bindings.createStringBinding(
                        () -> Integer.toString(scoreVO.getRecordId()), scoreVO.recordIdProperty()));
        examDateLabel.textProperty().bind(
                Bindings.createStringBinding(
                        () -> Objects.nonNull(scoreVO.getExamDate()) ?
                                scoreVO.getExamDate().toString() : Strings.EMPTY, scoreVO.examDateProperty()));
        scoreLabel.textProperty().bind(
                Bindings.createStringBinding(
                        () -> Double.toString(scoreVO.getScore()), scoreVO.scoreProperty()));
        studentNameLabel.textProperty().bind(
                Bindings.createStringBinding(
                        () -> Objects.nonNull(scoreVO.getStudent()) ?
                                scoreVO.getStudent().getName() : Strings.EMPTY, scoreVO.studentProperty()));
        courseNameLabel.textProperty().bind(
                Bindings.createStringBinding(
                        () -> Objects.nonNull(scoreVO.getCourse()) ?
                                scoreVO.getCourse().getName() : Strings.EMPTY, scoreVO.courseProperty()));
    }

    @Override
    public void initLayout() {

    }

    @Override
    public void loadData() {

    }
}
